package com.pro.controller;

import com.pro.pojo.JsComment;
import com.pro.pojo.JsCourse;
import com.pro.pojo.JsonData;
import com.pro.service.JsNewCourseCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author cyj
 * @date 2002.3.29$ 14.03$
 * @content :
 */
@RequestMapping("/courseComment")
@RestController
public class JsNewCourseCommentController {

    @Autowired
    private JsNewCourseCommentService service;


    /**
     * @author cyj
     * @date 2022.3.30$ 20.35$
     * @content : 获取后台人员评论计数
     */
    @RequestMapping("/getUserComment")
    public JsonData getUserComment(Integer id) {
        JsCourse comment = service.getUserComment(id);
        return comment!=null?JsonData.buildSuccess(comment):JsonData.buildError("服务器错误");
    }
    /**
     * @author cyj
     * @date 2022.3.30$ 20.29$
     * @content : 获取后台人员评论计数
     */
    @RequestMapping("/getBeforeComment")
    public JsonData getBeforeComment(Integer id) {
        JsCourse comment = service.getBeforeComment(id);
        return comment!=null?JsonData.buildSuccess(comment):JsonData.buildError("服务器错误");
    }
    /**
     * @author cyj
     * @date 2022.3.29$ 16.56$
     * @content : 获取后台人员评论计数
     */
    @RequestMapping("/getAfterTable")
    public JsonData getAfterTable(Integer type, Integer status, Integer page, Integer limit) {
        List<JsComment> comments = service.getAfterTable(type,status,page,limit);
        Integer count = service.countComm(type,"2",null);
        return comments!=null?JsonData.buildSuccess(comments,count):JsonData.buildError("服务器错误");
    }
    /**
     * @author cyj
     * @date 2022.3.29$ 15.41$
     * @content : 获取前台评论表
     */
    @RequestMapping("/getBeforeTable")
    public JsonData getBeforeTable(Integer type, Integer status, Integer page, Integer limit){
        List<JsComment> comments = service.getBeforeTable(type,status,page,limit);
        Integer count = service.countComm(type,"1",null);
        return comments!=null?JsonData.buildSuccess(comments,count):JsonData.buildError("服务器错误");
    }
    /**
     * @author cyj
     * @date 2022.3.25$ 14.47$
     * @content : 获取评论的计数
     */
    @RequestMapping("/countCourseComment")
    public JsonData countCourseComment(Integer type,String userType,String commentDate){
        System.err.println(commentDate);
        Integer history = service.countComm(type,userType,null);
        Integer historyPeo = service.countPeo(type,userType,null).size();
        Integer today = service.countComm(type,userType,commentDate);
        Integer todayPeo = service.countPeo(type,userType,commentDate).size();
        List list = new ArrayList();
        list.add(history);
        list.add(historyPeo);
        list.add(today);
        list.add(todayPeo);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
    /**
     * @author cyj
     * @date 2022.3.29$ 14.02$
     * @content : 评论个数统计
     */
    @RequestMapping("/CountCourseNum")
    public JsonData CountCourseNum(String userType,Integer type,String status){
        Integer count = service.CountCourseNum(userType,type,status);
        return count!=0?JsonData.buildSuccess(count):JsonData.buildError("服务器错误");
    }
}
